// 封装axios
import axios from 'axios'

const request = axios.create({
  // baseURL: 'http://localhost:3000',
  baseURL: process.env.BASE_API,
  timeout: 5000
})

request.interceptors.request.use(config => {
  // 拦截请求，请求头中添加token
  const token = sessionStorage.getItem('token')
  if (token) {
    config.headers.Authorization = token
  }
  return config
}, err => {
  return Promise.reject(err)
})

request.interceptors.response.use(res => {
  // 拦截响应，处理错误
  return res
}, err => {
  return Promise.reject(err)
})

export default request